﻿using System;
using System.Reflection;
using System.Web.Mvc;

namespace PrecompiledMvcViewEngineContrib
{
    [AttributeUsage(AttributeTargets.Method)]   
    public class CompiledViewAttribute:ActionFilterAttribute
    {
        /// <summary>
        /// Gets or sets the assembly name containing the compiled view. 
        /// If empty it's assumed to be the controller's assembly
        /// </summary>
        public string FromAssembly { get; set; }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (string.IsNullOrEmpty(FromAssembly))
            {
                FromAssembly = Assembly.GetAssembly(filterContext.Controller.GetType()).GetName().Name;
            }
            filterContext.HttpContext.Items["cview_assembly"] = FromAssembly;
        }
    }
}